package com.jcake.vimlike.internal;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CommandParser {

	private static Pattern commandPattern = Pattern.compile("^(?:\"([a-zA-Z0-9\\-\":.%#=*+~_/]))?(\\d+)?(\\w+(?:\\$|\\^)?)?$");
	private Character register;
	private Integer count;
	private String command;

	public CommandParser(String command) {
		parseCommand(command);
	}

	private void parseCommand(String command) {
		Matcher matcher = commandPattern.matcher(command);
		if (matcher.matches()) {
			if (matcher.group(1) != null) {
				this.register = matcher.group(1).charAt(0);
			}
			if (matcher.group(2) != null) {
				this.count = Integer.valueOf(matcher.group(2));
			}
			this.command = matcher.group(3);
		}
	}

	public Character getRegister() {
		return register;
	}

	public Integer getCount() {
		return count;
	}

	public String getCommand() {
		return command;
	}

}
